package com.share.user.api.factory;

import com.share.common.core.exception.ServiceException;
import com.share.user.api.RemoteUserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 *
 * @author share
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserInfoService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserInfoService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());

        throw new ServiceException("调用出现错误");
        // return new RemoteUserService()
        // {
        //     @Override
        //     public R<LoginUser> getUserInfo(String username, String source)
        //     {
        //         return R.fail("获取用户失败:" + throwable.getMessage());
        //     }
        //
        //     @Override
        //     public R<Boolean> registerUserInfo(SysUser sysUser, String source)
        //     {
        //         return R.fail("注册用户失败:" + throwable.getMessage());
        //     }
        // };
    }

    // 未使用到的方法
    // @Override
    // public R<UserInfo> wxLogin(String code, String source) {
    //     return R.fail("微信登录失败:" + throwable.getMessage());
    // }
    //
    // @Override
    // public R<Boolean> updateUserLogin(UpdateUserLogin updateUserLogin, String source) {
    //     return R.fail("更新用户登录失败:" + throwable.getMessage());
    // }
}
